//
//  THGoodDetailModel.m
//  TreeHole
//
//  Created by apple on 2020/9/16.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "THGoodDetailModel.h"

@implementation THGoodDetailModel
+ (NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{@"g_id":@"id"};
}
+ (NSDictionary *)mj_objectClassInArray{
    return @{@"groups":@"THGoodDetailModelGourpItemModel",@"specs":@"THGoodDetailModelSpecModel"};
}
- (NSString *)integral{
    if (STTools_UserManger.defult.stoneobs_fun_get_loginedUser.level.intValue != 1) {
        return @"0";
        
    }
    return _integral;
}
- (THGoodDetailModelSpecModel *)cus_selected_spec{
    if (!_cus_selected_spec) {
        _cus_selected_spec = self.specs.firstObject;
    }
    return _cus_selected_spec;
}
- (THGoodDetailModelGourpItemModel *)cus_selected_group{
    if (!_cus_selected_group) {
        _cus_selected_group = self.groups.firstObject;
    }
    return _cus_selected_group;
}
- (NSString *)cus_selected_spec_price{
    if (self.cus_selected_spec) {

        if (STTools_UserManger.defult.stoneobs_fun_get_loginedUser.level.intValue == 3) {
            //返回企业价格
            if (self.cus_selected_spec.cus_num >= self.business_num.integerValue) {
                return self.cus_selected_spec.business_price;
            }
            return self.cus_selected_spec.price;
        }
        if (STTools_UserManger.defult.stoneobs_fun_get_loginedUser.level.intValue == 2) {
            //返回小店价格
            if (self.cus_selected_spec.cus_num >= self.shop_num.integerValue) {
                return self.cus_selected_spec.shop_price;
            }
            return self.cus_selected_spec.price;
        }
        
        if (self.is_pt && !self.cus_pt_mine_buy) {
            return self.cus_selected_spec.pt_price;
        }
        if (self.is_sr) {
            return self.cus_selected_spec.sr_price;
        }
        if (self.is_xql) {
            return self.cus_selected_spec.xql_price;
        }

        return self.cus_selected_spec.price;
    }
    if (STTools_UserManger.defult.stoneobs_fun_get_loginedUser.level.intValue == 3) {
        //返回企业价格
        if (self.cus_num > self.business_num.integerValue) {
            return self.business_price;
        }
        return self.price;
    }
    if (STTools_UserManger.defult.stoneobs_fun_get_loginedUser.level.intValue == 2) {
        //返回小店价格
        if (self.cus_num > self.shop_num.integerValue) {
            return self.shop_price;
        }
        return self.price;
    }

    if (self.is_pt) {
        return self.pt_price;
    }
    if (self.is_sr) {
        return self.sr_price;
    }
    if (self.is_xql) {
        return self.xql_price;
    }
    if (_price.floatValue <= 0 ) {
        return self.old_price;
    }
    return _price;
}
- (bool)is_pt{
    if (STTools_UserManger.defult.stoneobs_fun_get_loginedUser.level.intValue > 1) {
        return NO;
    }
    return _is_pt;
}
- (bool)is_sr{
    if (STTools_UserManger.defult.stoneobs_fun_get_loginedUser.level.intValue > 1) {
        return NO;
    }
    return _is_sr;
}
- (bool)is_xql{
    if (STTools_UserManger.defult.stoneobs_fun_get_loginedUser.level.intValue > 1) {
        return NO;
    }
    return _is_xql;
}
- (NSString *)cus_type_selcted{
    if (!_cus_type_selcted) {
        _cus_type_selcted =  self.type_detail.firstObject;
    }
    return _cus_type_selcted;
}
@end

@implementation THGoodDetailModelGourpItemModel
+ (NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{@"group_id":@"id"};
}
@end
@implementation THGoodDetailModelSpecModel
+ (NSDictionary *)mj_replacedKeyFromPropertyName{
    return @{@"s_id":@"id"};
}
- (NSInteger )cus_num{
    if (!_cus_num) {
        _cus_num = 1;
    }
    return _cus_num;
}
- (NSString *)integral{
    if (STTools_UserManger.defult.stoneobs_fun_get_loginedUser.level.intValue != 1) {
        return @"0";
        
    }
    return _integral;
}
@end

